<?php
namespace App\Http\Controllers\Mp;
use App\Models\BookRule;
use App\Services\BookOrderService;
use Illuminate\Http\Request;
use App\Models\BookOrder;
use App\Http\Resources\Mp\BookOrderResource;
/**
 * Class AdditionOrderController
 * @package App\Http\Controllers\Mp
 * @author zjw
 */
class AdditionOrderController extends BaseController{

    public function index() {
        $query = BookOrder::belongToUser()->isAddition()->with('rule')->orderBy("created_at",'desc');
        return BookOrderResource::collection($query->paginate(10));
    }


    public function store(Request $request){
        $ruleId = $request->rule_id;
        $rule = BookRule::schoolIs(\Auth::user()->school_id)->find($ruleId);
        if(!$rule) {
            return $this->fail('表单填写不完整');
        }
        $num = $request->input("num",1);
        BookOrderService::generateAdditionOrder(\Auth::user(),$rule , $num);
        return [];
    }
}
